package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;

import com.itheima.health.entity.MemberDto;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/mobile/order")
public class OrderController {


    @Autowired
    private OrderService orderService;


    @PostMapping("/submit")
    public Result submit(@RequestBody MemberDto memberDto, HttpSession httpSession) {
        log.info("[预约提交],memberDto:{}", memberDto);
        Order order = orderService.submit(memberDto,httpSession);
        log.info("[order],{}",order);
        return new Result(true, MessageConst.ORDER_SUCCESS,order);
    }

    /**
     * 任务11 体检预约-订单数据展示
     * @param order
     * @return
     *///localhost:17080/mobile/order/findById?id=
    @GetMapping("/findById")
    public Result findById(Order order) {
        log.info("[id为：]{}", order.getId());

        Map orderInfo = orderService.findById(order.getId());

        return new Result(true, MessageConst.ACTION_SUCCESS, orderInfo);
    }


}
